
global maps "GIS_shapefiles"


clear
clear matrix 
clear mata
set maxvar 10000



spshape2dta "$maps/World_Countries_Generalized", saving(world) replace

*Read the id crosswalk that we'll be using to match the countries with their coordinates
use world, clear
keep _ID _CX COUNTRY ISO COUNTRYAFF

gen origin = COUNTRY
replace origin = "Brunei" if origin == "Brunei Darussalam"
replace origin = "Cape Verde" if origin == "Cabo Verde"
replace origin = "Democratic Republic of the Congo" if origin == "Congo DRC"
replace origin = "Cote d'Ivoire" if origin == "Côte d'Ivoire"
replace origin = "Kyrgyz Republic" if origin == "Kyrgyzstan"
replace origin = "Russia" if origin == "Russian Federation"
replace origin = "Slovak Republic" if origin == "Slovakia"
replace origin = "Timor" if origin == "Timor-Leste"
replace origin = "Turkey" if origin == "Turkiye"
duplicates drop origin, force
drop if origin == ""


preserve
use "Data_Duties_Master.dta", clear
keep if year == 2017
tempfile main_data
save `main_data'
restore

*merge master and ID crosswalk
merge 1:1 origin using `main_data', keepusing(duties_total)


*193 with countryaff and manual modifications (out of 197 countries available in main data for 2018). Countries in main data that do not get matched: Abkhazia, Kosovo, South Ossetia, Taiwan

drop if COUNTRY == "Antarctica" | COUNTRY == "Greenland" | COUNTRY == "Svalbard"
*dropping countries for which we did not find the coordinates in the world bank data (Abkhazia, Solomon Islands, South Ossetia, Taiwan)
drop if missing(_ID)
*Draw Maps

set scheme white_tableau


*******Duties*******
spmap duties_total using world_shp, id(_ID) fcolor(Blues) ocolor(gs2 ..) osize(0.03 ..) legend(pos(6) ring(6) size(3) rows(1) title("Total", size(4))) legstyle(2)  clmethod(custom) clbreaks(0 1 5 10 15) 
graph export "Figure_3.pdf", replace
